#include <iostream>
#include <signal.h>
#include <unistd.h>

void handlerSig(int signum)
{
    std::cout << "进程 " << getpid() << " 收到信号 " << signum << "，开始处理..." << std::endl;

    while (true)
    {
        // 不断获取pending表
        sigset_t pending;
        sigpending(&pending);
        for (int i = 31; i >= 1; i--)
        {
            if (sigismember(&pending, i))
                std::cout << "1";
            else
                std::cout << "0";
        }
        std::cout << std::endl;
        sleep(1);
    }
    exit(0);
}

int main()
{
    struct sigaction act, oact; 
    act.sa_handler = handlerSig;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, 3);
    sigaddset(&act.sa_mask, 4);
    act.sa_flags = 0;

    sigaction(SIGINT, &act, &oact);

    while(true)
    {
        std::cout << "进程 " << getpid() << " 等待信号..." << std::endl;
        sleep(1);
    }

    return 0;
}